﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace ExplorerPlus
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            //Initialize Logging
            log4net.Config.XmlConfigurator.Configure();
            Application.Run(new ExplorerPlus());
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            LogError(sender, e.Exception);

            MessageBox.Show("An unexpected error ocurred, the error information has been logged to:\n"
                + AppDomain.CurrentDomain.BaseDirectory + "errors.log"
                + "\nIf this error continues to appear, then please contact us at http://explorerplus.codeplex.com/ and send us the log file to trace and fix this error.", "Error");
        }

        public static void LogError(object sender, Exception e)
        {
            // log error
            if (sender != null)
                log4net.LogManager.GetLogger(sender.GetType().FullName).Error(e.Message, e);
            else
                log4net.LogManager.GetLogger("LogManager").Error(e.Message, e);
        }
    }
}
